<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      v-loading="loading"
      v-loading.fullscreen.lock="fullscreenLoading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      :data="data"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import ss from '@/api/edu/subject'

export default {

  data() {
    return {
      filterText: '',
      loading: false,
      fullscreenLoading: false,
      data: [],
      defaultProps: {
        children: 'children',
        label: 'label',
        desc: 'desc'
      }
    }
  },
  created() {
    this.fetchData()
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
  methods: {
    fetchData: function () {
      // this.loading = true
      this.fullscreenLoading = true
      ss.getList().then(response => {
        // this.loading = false
        this.fullscreenLoading = false
        this.data = response.data.result;
      })
    },

    filterNode(value, data) {
      if (!value) return true
      return data.label.toLowerCase().indexOf(value.toLowerCase()) !== -1
    }
  }
}
</script>

